package com.yyk.yykywd.mvvm.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yyk.yykywd.*
import com.yyk.yykywd.http.ApiService
import com.yyk.yykywd.mvvm.entity.PotentialCustomerBean

/**
 * 文件描述：
 * Created by guo on 2019-12-02.
 */
class PotentialCustomerAdapter(private val context: Context,
                               private val type: String,
                               layoutResId: Int,
                               data: List<PotentialCustomerBean.Data>) : BaseQuickAdapter<PotentialCustomerBean.Data, BaseViewHolder>(layoutResId, data) {
    override fun convert(helper: BaseViewHolder, item: PotentialCustomerBean.Data) {
        val clHospital: ConstraintLayout = helper.getView(R.id.cl_hospital)
        val tvIntoHighSea: TextView = helper.getView(R.id.tv_into_high_sea)
        val tvSiteNumHint: TextView = helper.getView(R.id.tv_site_num_hint)
        val tvSiteNum: TextView = helper.getView(R.id.tv_site_num)
        val clAgent: ConstraintLayout = helper.getView(R.id.cl_agent)
        val tv_type: TextView = helper.getView(R.id.tv_type)
        val tvStatus: TextView = helper.getView(R.id.tv_customer_status)
        if (item.client_type == 1) {
            tv_type.setBackgroundResource(R.color.col_68c3d4)
            clHospital.visibility = View.VISIBLE
            clAgent.visibility = View.GONE
            if (type == POTENTIAL_CUSTOMER) {
                helper.setText(R.id.tv_hospital_name, item.hos_name)
                helper.setText(R.id.tv_hospital_type, item.type_name)
                helper.setText(R.id.tv_visitor, item.call_name)
                helper.setText(R.id.tv_contact, item.call_phone)
            } else if (type == C_CUSTOMER) {
                helper.setText(R.id.tv_hospital_name, item.hos_name)
                helper.setText(R.id.tv_hospital_type, item.type_name)
                helper.setText(R.id.tv_visitor, item.fname)
                helper.setText(R.id.tv_contact, item.phone)
            } else if (type == SIGN_CONTRACT) {
                helper.setText(R.id.tv_hospital_name, item.clientname)
                helper.setText(R.id.tv_hospital_type, item.type_name)
                helper.setText(R.id.tv_visitor, item.call_name)
                helper.setText(R.id.tv_contact, item.call_phone)
            }

        } else {
            tv_type.setBackgroundResource(R.color.col_f5c161)
            clHospital.visibility = View.GONE
            clAgent.visibility = View.VISIBLE
            if (type == POTENTIAL_CUSTOMER) {
                helper.setText(R.id.tv_agent, item.hos_name)
                helper.setText(R.id.tv_agent_contact, item.call_phone)
                helper.setText(R.id.tv_agent_region, item.type_name)
            } else if (type == C_CUSTOMER) {
                helper.setText(R.id.tv_agent, item.hos_name)
                helper.setText(R.id.tv_agent_contact, item.phone)
                helper.setText(R.id.tv_agent_region, item.type_name)
            } else if (type == SIGN_CONTRACT) {
                helper.setText(R.id.tv_agent, item.clientname)
                helper.setText(R.id.tv_agent_contact, item.call_phone)
                helper.setText(R.id.tv_agent_region, item.type_name)
            }
        }
        if (type == POTENTIAL_CUSTOMER) {
            tvIntoHighSea.visibility = View.VISIBLE
            tvSiteNumHint.visibility = View.GONE
            tvSiteNum.visibility = View.GONE
            helper.setText(R.id.tv_customer_status, item.types_wz)
            tvStatus.setBackgroundResource(R.drawable.shape_2dp2)
            tvStatus.setTextColor(ContextCompat.getColor(context, R.color.col_e61a13))
            helper.setText(R.id.tv_founder, getPersonName(item.name, item.get_name))
            helper.setText(R.id.tv_create_time, getTime(item.name, item.create_time, item.update_time))
            if (item.add_gh_day == 0) {
                helper.setText(R.id.tv_into_high_sea, "于今晚24:00流至公海")
            } else {
                helper.setText(R.id.tv_into_high_sea, item.add_gh_day.toString() + "天后流至公海")
            }

        } else if (type == C_CUSTOMER) {
            tvIntoHighSea.visibility = View.VISIBLE
            tvSiteNumHint.visibility = View.GONE
            tvSiteNum.visibility = View.GONE
            helper.setText(R.id.tv_customer_status, "C类客户")
            tvStatus.setBackgroundResource(R.drawable.shape_2dp4)
            tvStatus.setTextColor(ContextCompat.getColor(context, R.color.col_5987ff))
            if (item.belong_type == 1) {
                helper.setText(R.id.tv_founder, "创建人：" + item.name)
                helper.setText(R.id.tv_create_time, "创建时间：" + getCommonTime(item.create_time))
            } else {
                helper.setText(R.id.tv_founder, "认领人：" + item.usname)
                helper.setText(R.id.tv_create_time, "认领时间：" + getCommonTime(item.update_time))
            }
            if (item.add_gh_day == 0) {
                helper.setText(R.id.tv_into_high_sea, "于今晚24:00流至公海")
            } else {
                helper.setText(R.id.tv_into_high_sea, item.add_gh_day.toString() + "天后流至公海")
            }
        } else if (type == SIGN_CONTRACT) {
            tvIntoHighSea.visibility = View.GONE
            tvSiteNumHint.visibility = View.VISIBLE
            tvSiteNum.visibility = View.VISIBLE
            tvSiteNum.text = item.agency_count.toString()
            helper.setText(R.id.tv_customer_status, item.flag_wz)
            tvStatus.setBackgroundResource(R.drawable.shape_2dp2)
            tvStatus.setTextColor(ContextCompat.getColor(context, R.color.col_e61a13))
            helper.setText(R.id.tv_founder, getPersonName(item.name, item.get_name))
            helper.setText(R.id.tv_create_time, getTime(item.name, item.cretime, item.upd_time))
        }
    }
}